package com.example.myapplication.provider;


import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.*;
import ohos.app.Context;
import ohos.global.resource.*;
import ohos.agp.components.Image;

import java.util.List;

public class IndexImgPageSliderProvider extends PageSliderProvider {
    private List<Integer> imageResPaths;
    private Context context;
    private ResourceManager resourceManager;
    private AbilitySlice abilitySlice;

    public IndexImgPageSliderProvider(List<Integer> imageResPaths, AbilitySlice abilitySlice) {
        this.imageResPaths = imageResPaths;

        this.abilitySlice = abilitySlice;
    }

    // ... 其他方法

    @Override
    public Object createPageInContainer(ComponentContainer componentContainer, int position) {
        // 获取轮播图模板
        DirectionalLayout template = (DirectionalLayout) LayoutScatter.getInstance(abilitySlice).parse(ResourceTable.Layout_index_img_template, null, false);
        Image image = (Image) template.findComponentById(ResourceTable.Id_index_image);

        // 根据 position 设置不同的图片资源
        switch (position) {
            case 0:
                image.setPixelMap(ResourceTable.Media_img01);
                break;
            case 1:
                image.setPixelMap(ResourceTable.Media_img02);
                break;
            case 2:
                image.setPixelMap(ResourceTable.Media_img04);
                break;
            default:
                image.setPixelMap(ResourceTable.Media_img01); // 默认图片
                break;
        }

        // 将图片模板绑定到 pageSlider
        componentContainer.addComponent(template);
        return template;
    }
    @Override
    public void destroyPageFromContainer(ComponentContainer componentContainer, int position, Object object) {
        componentContainer.removeComponent((Component) object);
    }

    @Override
    public int getCount() {
        return imageResPaths.size();
    }

    @Override
    public boolean isPageMatchToObject(Component component, Object object) {
        return component == object;
    }
}